package com.Questions.elseQuestion;


/**
 * 查询网格中每一列的宽度
 */
public class leetcode2639 {
    public int[] findColumnWidth(int[][] grid) {
        int[] ans = new int[grid[0].length];
        for (int i = 0; i < grid[0].length; ++i) {// 遍历列
            int maxLen = 1;
            for(int j = 0; j < grid.length; ++j) {// 遍历行
                maxLen = Math.max(maxLen, lenOfInt(grid[j][i]));
            }
            ans[i] = maxLen;
        }
        return ans;
    }

    private int lenOfInt(int num) {// 求取整数的字符串长度
        int len = 0;
        if (num < 0){
            len = 1;
            num = Math.abs(num);
        }
        while (num > 0) {
            num /= 10;
            len++;
        }
        return len;
    }
}
